package demo1218.homework;

import java.util.Calendar;
import java.util.Scanner;

public class Demo_02 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个年份:");//2020
        int year = scan.nextInt();
        System.out.println("请输入一个月份:");//12
        int month = scan.nextInt();
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, 1);//2020 12 1
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        int maximum = cal.getActualMaximum(Calendar.DATE);
        System.out.println();
        //打印的是-- 把1号之前的--都打印出来
        for (int i = 1; i < cal.get(Calendar.DAY_OF_WEEK); i++) {
            System.out.print("--\t");
        }
        for (int i = 1; i <= maximum; i++) {
            if (cal.get(Calendar.DAY_OF_WEEK) % 7 == 0) {
                System.out.println(cal.get(Calendar.DATE) + "\t");
            } else {
                System.out.print(cal.get(Calendar.DATE) + "\t");
            }
            cal.add(Calendar.DATE, 1);
        }
    }
}
